package dao.mybatis;

import java.io.Serializable;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class MybatisCommonDao implements IMybatisCommonDao {
	private SqlSessionFactory sqlSessionFactory;

	private SqlSession getsession() {
		return sqlSessionFactory.openSession();
	}

	public List selectlist(String statement, Object parameter) {
		return getsession().selectList(statement, parameter);
	}

	public void delete(String statement, Object parameter) {
		getsession().delete(statement, parameter);
	}

	public void update(String statement, Object parameter) {
		getsession().update(statement, parameter);
	}

	public Object findbyId(String statement, Serializable id) {
		return getsession().selectOne(statement, id);
	}

	/**
	 * @return the sqlSessionFactory
	 */
	public SqlSessionFactory getSqlSessionFactory() {
		return sqlSessionFactory;
	}

	/**
	 * @param sqlSessionFactory
	 *            the sqlSessionFactory to set
	 */
	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}

	@Override
	public void save(String statement, Object parameter) {
		getsession().insert(statement, parameter);

	}

	@Override
	public Object getByEntity(String statement, Object parameter) {
		// TODO Auto-generated method stub
		return getsession().selectOne(statement, parameter);
	}
}
